import { userAccountLogin } from '../../api/user'
// 用户状态
export default {
  namespaced: true,
  // 定义变量
  // 登录人信息
  state: () => ({
    profile: {
      id: '',
      avatar: '',
      nickname: '',
      account: '',
      mobile: '',
      token: ''
    }
  }),
  mutations: {
    // 储存数据
    setprofile (state, profile) {
      state.profile = profile
    },
    // 删除数据
    delprofile (state) {
      state.profile = {}
    }
  },
  actions: {
    async getprofile ({ commit }, payload) {
      const { result } = await userAccountLogin(payload)
      commit('setprofile', result)
    },
    logout ({ commit }) {
      commit('delprofile')
      commit('cart/delChartAction', [], { root: true })
    }
  }
}
